import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'constants/themes.dart';
import 'providers/app_state.dart';
import 'pages/introduction_page.dart';
import 'pages/basic_info_page.dart';
import 'pages/questionnaire_page.dart';
import 'pages/result_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => AppState(),
      child: Consumer<AppState>(
        builder: (context, appState, child) {
          return MaterialApp(
            title: 'SCL-90 心理健康评估',
            theme: AppThemes.getTheme(appState.currentTheme),
            home: const MainScreen(),
            debugShowCheckedModeBanner: false,
          );
        },
      ),
    );
  }
}

class MainScreen extends StatelessWidget {
  const MainScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Consumer<AppState>(
      builder: (context, appState, child) {
        switch (appState.currentPageIndex) {
          case 0:
            return const IntroductionPage();
          case 1:
            return const BasicInfoPage();
          case 2:
            return const QuestionnairePage();
          case 3:
            return const ResultPage();
          default:
            return const IntroductionPage();
        }
      },
    );
  }
}
